package com.audaque.springboot.foshanupload.web.productdemo.controller;

import com.audaque.springboot.foshanupload.web.productdemo.entity.Rule;
import com.audaque.springboot.foshanupload.web.productdemo.req.RuleReq;
import com.audaque.springboot.foshanupload.web.productdemo.service.IRuleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 规则 前端控制器
 * </p>
 *
 * @author zgb
 * @since 2024-04-22
 */
@RestController

@Api(value = "规则 前端控制器")

@RequestMapping("/rule")
public class RuleController {


    @Autowired
    private IRuleService iRuleService;

    @PostMapping(value = "/page")
    @ApiOperation(value = "规则 分页查询")
    public Page<Rule> page(@RequestBody RuleReq req) {
        QueryWrapper queryWrapper = new QueryWrapper(req);
        Page<Rule> page = iRuleService.page(new Page<>(req.getCurrent(), req.getSize()), queryWrapper);
        return page;
    }


    @PostMapping(value = "/list")
    @ApiOperation(value = "规则 列表查询")
    public List<Rule> list(@RequestBody RuleReq req) {
        QueryWrapper queryWrapper = new QueryWrapper(req);
        List<Rule> list = iRuleService.list(queryWrapper);
        return list;
    }


    @GetMapping(value = "/{id}")
    @ApiOperation(value = "规则 单体查询")
    public Rule getById(@PathVariable("id") String id) {
        Rule one = iRuleService.getById(id);
        return one;
    }

    @PostMapping(value = "/create")
    @ApiOperation(value = "规则 创建")
    public void create(@RequestBody Rule params) {
        iRuleService.save(params);
    }

    @PostMapping(value = "/delete/{id}")
    @ApiOperation(value = "规则 删除")
    public void delete(@PathVariable("id") String id) {
        iRuleService.removeById(id);
    }

    @PostMapping(value = "/update")
    @ApiOperation(value = "规则 更新")
    public void update(@RequestBody Rule params) {
        iRuleService.updateById(params);
    }
}
